package com.gidas.client;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.maps.client.geocode.DirectionQueryOptions;
import com.google.gwt.maps.client.geocode.DirectionResults;
import com.google.gwt.maps.client.geocode.Directions;
import com.google.gwt.maps.client.geocode.DirectionsCallback;
import com.google.gwt.maps.client.geocode.Waypoint;

public class Route {
	private List<ObjectSerializable> objectList = null;
	
	
	public Route() {
		objectList = new ArrayList<ObjectSerializable>();
	}

	public int getObjectsTime() {
		if (objectList != null && !objectList.isEmpty()) {
			int time = 0;
			for (ObjectSerializable o : objectList) {
				time += o.getTakesTimeMinutes();
			}

			return time;
		} else
			return 0;
	}

	public boolean addObject(ObjectSerializable o) {
		if (checkIfNew(o)) {
			objectList.add(o);
			return true;
		}
		return false;
	}

	public boolean removeObject(ObjectSerializable o) {
		if (objectList.remove(o)) {
			return true;
		} else
			return false;
	}

	
	public boolean checkIfNew(ObjectSerializable object) {
		for (ObjectSerializable o : objectList) {
			Long id = o.getId();
			System.out.println("o="+o.getId()+" ir object="+object.getId()+ " : "+id.compareTo(object.getId()));
			
			if (id.compareTo(object.getId()) == 0) {
				
				return false;
			}
		}
		return true;
	}

	public void traceObjects() {
		for (ObjectSerializable o : objectList) {
			System.out.println(o.getName() + " - " + o.getId());
		}
	}

	public void setObjectList(List<ObjectSerializable> objectList) {
		this.objectList = objectList;
	}

	public List<ObjectSerializable> getObjectList() {
		return objectList;
	}
}
